function [shad_all,vis_fl_all,pert_num]=meta_analysis_get_vars(proj_meta,cur_site,order,exp_inds)

shad_all={};
vis_fl_all={};
% delta_all={};
pert_num={};
for tnd=1:size(proj_meta(cur_site).rd,2)
    cur_pert_num=[];
    ps_id=proj_meta(cur_site).rd(1,tnd).ps_id;
    runM=proj_meta(cur_site).rd(1,tnd).velM_smoothed>0.01;
    runP=proj_meta(cur_site).rd(1,tnd).velP_smoothed>0.01;
%     pupil_pos=proj_meta(cur_site).rd(1,tnd).pupil_pos;
    shad=[];
    vis_fl=[];
    cnt=1;
    for bnd=1:length(order{tnd})
        if order{tnd}(bnd)==1
            tmp_runM=runM(exp_inds{tnd}(bnd,1):exp_inds{tnd}(bnd,2));
            tmp_ps_id=ps_id(exp_inds{tnd}(bnd,1):exp_inds{tnd}(bnd,2));
            for fnd=1:length(tmp_runM)
                if tmp_runM(fnd)==0
                    shad(cnt)=0;
                    vis_fl(cnt)=0;
                    cnt=cnt+1;
                elseif tmp_runM(fnd)==1 & logical(tmp_ps_id(fnd))==0 %feedback
                    shad(cnt)=1;
                    vis_fl(cnt)=1;
                    cnt=cnt+1;
                elseif tmp_runM(fnd)==1 & logical(tmp_ps_id(fnd))==1 %feedback mismatch
                    if tmp_ps_id(fnd)==7
                        shad(cnt)=2;
                        vis_fl(cnt)=0;
                        cnt=cnt+1;
                    else
                        cur_pert_num(cnt)=tmp_ps_id(fnd);
%                         shad(cnt)=4;
                        shad(cnt)=tmp_ps_id(fnd)+9;
                        vis_fl(cnt)=1;
                        cnt=cnt+1;
                    end
                end
            end
        elseif order{tnd}(bnd)==2
            tmp_runM=runM(exp_inds{tnd}(bnd,1):exp_inds{tnd}(bnd,2));
            tmp_ps_id=ps_id(exp_inds{tnd}(bnd,1):exp_inds{tnd}(bnd,2));
            tmp_runP=runP(exp_inds{tnd}(bnd,1):exp_inds{tnd}(bnd,2));
            for fnd=1:length(tmp_runM)
                if logical(tmp_ps_id(fnd))==0 & tmp_runM(fnd)==0 & tmp_runP(fnd)==0 | logical(tmp_ps_id(fnd))==1 & tmp_runM(fnd)==0 & tmp_runP(fnd)==0
                    shad(cnt)=0;
                    vis_fl(cnt)=0;
                    cnt=cnt+1;
                elseif logical(tmp_ps_id(fnd))==1 & tmp_runM(fnd)==0 & tmp_runP(fnd)==1
                    if tmp_ps_id(fnd)==7
                        shad(cnt)=16;
                        vis_fl(cnt)=0;
                        cnt=cnt+1;
                    else
                        cur_pert_num(cnt)=tmp_ps_id(fnd);
                        shad(cnt)=tmp_ps_id(fnd)+23;
                        vis_fl(cnt)=1;
                        cnt=cnt+1;
                    end
                elseif logical(tmp_ps_id(fnd))==0 & tmp_runM(fnd)==0 & tmp_runP(fnd)==1
                    shad(cnt)=30;
                    vis_fl(cnt)=1;
                    cnt=cnt+1;
                elseif logical(tmp_ps_id(fnd))==0 & tmp_runM(fnd)==1 & tmp_runP(fnd)==1
                    shad(cnt)=31;
                    vis_fl(cnt)=1;
                    cnt=cnt+1;
                elseif logical(tmp_ps_id(fnd))==0 & tmp_runM(fnd)==1 & tmp_runP(fnd)==0 | logical(tmp_ps_id(fnd))==1 & tmp_runM(fnd)==1 & tmp_runP(fnd)==0
                    shad(cnt)=32;
                    vis_fl(cnt)=0;
                    cnt=cnt+1;
                elseif logical(tmp_ps_id(fnd))==1 & tmp_runM(fnd)==1 & tmp_runP(fnd)==1
                    if tmp_ps_id(fnd)==7
                        shad(cnt)=33;
                        vis_fl(cnt)=0;
                        cnt=cnt+1;
                    else
                        cur_pert_num(cnt)=tmp_ps_id(fnd);
                        shad(cnt)=tmp_ps_id(fnd)+40;
                        vis_fl(cnt)=1;
                        cnt=cnt+1;
                    end
                end
            end
        end
    end
    shad(length(shad)+1:length(runM))=0;
    shad_all{tnd}=shad;
    vis_fl(length(vis_fl)+1:length(runM))=0;
    vis_fl_all{tnd}=vis_fl;
%     delta=sqrt(diff(pupil_pos(1,:)).^2+diff(pupil_pos(2,:)).^2);
%     delta(end+1)=delta(end);
%     delta_all{tnd}=delta;
    pert_num{tnd}=cur_pert_num;
end

